var n = ["", "K", "M", "G", "B", "T", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar"];
function o(e, t) {
  var n = [e, t];
  if (e.length < t.length) {
    n[0] = t;
    n[1] = e;
    n[2] = "not";
    return n;
  }
  if (e.length == t.length) {
    for (var o = 0; o < e.length; o++) {
      if (n[0][o] > n[1][o]) {
        n[0] = e;
        n[1] = t;
        return n;
      }
      if (n[0][o] < n[1][o]) {
        n[0] = t;
        n[1] = e;
        n[2] = "not";
        return n;
      }
      if (o == e.length - 1) {
        return n;
      }
    }
  }
  if (e.length > t.length) {
    return n;
  } else {
    return undefined;
  }
}
function i(e) {
  if (0 == e) {
    return 0;
  }
  var t = (e = e.split("")).length;
  for (var n = 0; n < t && 0 == e[0]; n++) {
    e.splice(0, 1);
  }
  return e;
}
var s = ["", "K", "M", "B", "T"];
for (var a = 0; a < 2; a++) {
  for (var r = 0; r < 26; r++) {
    s.push(String.fromCharCode(65 + a) + String.fromCharCode(65 + r));
  }
}
window.Number_util = {
  unit_format(e) {
    var t = "";
    if ((e = e.toString()).length > 6) {
      var n = parseInt(e.length / 3);
      var o = e.length % 3;
      t = s[n -= 0 == o ? 2 : 1];
      e = e.substr(0, e.length - 3 * n);
    }
    return this.number_format(e, 0, ",") + t;
  },
  number_format(e, t, n) {
    e = (e + "").replace(/[^0-9+-Ee.]/g, "");
    var o = isFinite(+e) ? +e : 0;
    var i = isFinite(+t) ? Math.abs(t) : 0;
    var s = undefined === n ? "," : n;
    var a = "";
    a = (i ? function (e, t) {
      var n = Math.pow(10, t);
      return "" + Math.ceil(e * n) / n;
    }(o, i) : "" + Math.round(o)).split(".");
    for (var r = /(-?\d+)(\d{3})/; r.test(a[0]);) {
      a[0] = a[0].replace(r, "$1" + s + "$2");
    }
    if ((a[1] || "").length < i) {
      a[1] = a[1] || "";
      a[1] += new Array(i - a[1].length + 1).join("0");
    }
    return a.join(".");
  },
  setNumberLength(e, t) {
    for (e = e.toString(); e.length < t;) {
      e = "0" + e;
    }
    return e;
  },
  time_format(e) {
    var t = this.setNumberLength(Math.floor(e / 3600), 2);
    e %= 3600;
    return t + ":" + this.setNumberLength(Math.floor(e / 60), 2) + ":" + this.setNumberLength(e % 60, 2);
  },
  sortByType(e, t) {
    return e.sort(function (e) {
      return function (t, n) {
        var o;
        var i;
        if ("object" == typeof t && "object" == typeof n && t && n) {
          if ((o = t[e]) === (i = n[e])) {
            return 0;
          } else {
            if (typeof o == typeof i) {
              if (o < i) {
                return -1;
              } else {
                return 1;
              }
            } else {
              if (typeof o < typeof i) {
                return -1;
              } else {
                return 1;
              }
            }
          }
        }
        throw "error";
      };
    }(t));
  },
  countTime(e, t) {
    t(e);
    var n = setInterval(function () {
      if (--e >= 0) {
        t(e);
      } else {
        cc.log("stop Interval=" + n);
        clearInterval(n);
      }
    }.bind(this), 1e3);
    return n;
  },
  clearInterval: function (e) {
    function t(t) {
      return e.apply(this, arguments);
    }
    t.toString = function () {
      return e.toString();
    };
    return t;
  }(function (e) {
    cc.log("clearInterval=" + e);
    clearInterval(e);
  }),
  isOneDay(e, t) {
    var n = new Date(parseInt(e));
    var o = new Date(parseInt(t));
    return n.getFullYear() == o.getFullYear() && n.getMonth() == o.getMonth() && n.getDate() == o.getDate();
  },
  randomNum(e, t) {
    switch (arguments.length) {
      case 1:
        return parseInt(Math.random() * e + 1, 10);
      case 2:
        return parseInt(Math.random() * (t - e + 1) + e, 10);
      default:
        return 0;
    }
  },
  convertNumber(e) {
    var t = String(e);
    var o = t.length;
    var i = "";
    if (o < 5) {
      return t;
    }
    var s = Math.floor((o - 1) / 3);
    var a = o - 3 * s;
    for (var r = 0; r < a + 2; r++) {
      i += t[r];
      r == a - 1 && (i += ".");
    }
    for (var l = i.length - 1; l >= 0; l--) {
      if ("0" != i[l]) {
        if ("." == i[l]) {
          i = i.substring(0, i.length - 1);
          break;
        }
        break;
      }
      i = i.substring(0, i.length - 1);
    }
    return i + n[s];
  },
  galaxyAdd(e, t) {
    var n;
    var i = [String(e), String(t)];
    var s = [];
    (i = o(i[0], i[1]))[0] = i[0].split("");
    i[1] = i[1].split("");
    if (i[0].length != i[1].length) {
      n = new Array(i[0].length - i[1].length + 1).join("0");
      i[1] = n.split("").concat(i[1]);
    }
    var a = 0;
    for (var r = i[0].length - 1; r >= 0; r--) {
      var l = Number(i[0][r]) + Number(i[1][r]) + a;
      s.unshift(l % 10);
      a = Math.floor(l / 10);
      0 == r && 0 != a && s.unshift(a);
    }
    return s.join("");
  },
  galaxySub(e, t) {
    var n;
    var s = [String(e), String(t)];
    var a = [];
    if (3 == (s = o(s[0], s[1])).length) {
      return false;
    }
    s[0] = s[0].split("");
    s[1] = s[1].split("");
    if (s[0].length != s[1].length) {
      n = new Array(s[0].length - s[1].length + 1).join("0");
      s[1] = n.split("").concat(s[1]);
    }
    var r = 0;
    for (var l = s[0].length - 1; l >= 0; l--) {
      var c = Number(s[0][l]) - Number(s[1][l]) - r;
      r = 0;
      if (c < 0) {
        c += 10;
        r = 1;
      }
      a.unshift(c % 10);
    }
    var d = a.join("");
    0 == d[0] && (d = i(d));
    var h = "";
    for (var u = 0; u < d.length; u++) {
      h += "" + d[u];
    }
    "" == h && (h = "0");
    return h;
  },
  galaxyMut(e, t) {
    var n;
    var s = "number" == typeof (n = t) ? null != n.toString().split(".")[1] ? n.toString().split(".")[1].length : 0 : "string" == typeof n ? null != n.split(".")[1] ? n.split(".")[1].length : 0 : undefined;
    s > 0 && (t = String(t).replace(".", ""));
    var a = [String(e), String(t)];
    var r = [];
    (a = o(a[0], a[1]))[0] = a[0].split("");
    a[1] = a[1].split("");
    if (-1 != a[0].indexOf("N") || -1 != a[1].indexOf("N")) {
      return e;
    }
    for (var l = a[1].length - 1; l >= 0; l--) {
      var c;
      var d = 0;
      var h = [];
      for (var u = a[0].length - 1; u >= 0; u--) {
        var g = Number(a[0][u]) * Number(a[1][l]) + d;
        h.unshift(g % 10);
        d = Math.floor(g / 10);
        0 == u && 0 != d && h.unshift(d);
      }
      c = new Array(a[1].length - (l + 1) + 1).join("0");
      h.push(c);
      r[l] = h.join("");
    }
    var f = r.length;
    for (var p = 1; p < f; p++) {
      var m = this.galaxyAdd(r[0], r[1]);
      r.splice(0, 2, m);
    }
    var w = r.join("");
    0 == w[0] && (w = i(w));
    var v = "";
    for (var y = 0; y < w.length - s; y++) {
      parseInt(w[y]) >= 0 && (v += "" + w[y]);
    }
    "" == v && (v = "0");
    return v;
  },
  galaxyDiv(e, t) {
    e = String(e);
    t = String(t);
    var n = e.length;
    t.length;
    var o = 0;
    var i = 0;
    var s = [];
    var a = 0;
    for (var r = 0; r < n; r++) {
      if ((a = 10 * i + parseInt(e[r])) < t) {
        i = a;
        s.push(0);
      } else {
        o = parseInt(a / t);
        i = a % t;
        s.push(o);
      }
    }
    return [o = "" == (o = s.join("").replace(/\b(0+)/gi, "")) ? "0" : o, i];
  },
  cmpBigInt(e, t) {
    e = String(e);
    t = String(t);
    if (e.length > t.length) {
      return 1;
    }
    if (e.length < t.length) {
      return -1;
    }
    for (var n = 0; n < e.length; n++) {
      if (e[n] > t[n]) {
        return 1;
      }
      if (e[n] < t[n]) {
        return -1;
      }
    }
    return 0;
  },
  compare(e, t) {
    return this.cmpBigInt(e, t) >= 0;
  },
  millisecondToDate(e) {
    e < 500 && (e = 0);
    var t = parseFloat(e) / 1e3;
    var n = parseInt(t / 3600);
    var o = parseInt(60 * (parseFloat(t / 3600) - parseInt(t / 3600)));
    var i = parseInt(60 * (parseFloat(60 * (parseFloat(t / 3600) - parseInt(t / 3600))) - parseInt(60 * (parseFloat(t / 3600) - parseInt(t / 3600)))));
    return (n = n < 10 ? "0" + n : n) + ":" + (o = o < 10 ? "0" + o : o) + ":" + (i < 10 ? "0" + i : i);
  },
  millisecondToMinute(e) {
    e < 500 && (e = 0);
    var t = parseFloat(e) / 1e3;
    var n = parseInt((t / 60).toString());
    var o = parseInt((t - 60 * n).toString());
    return (n < 10 ? "0" + n : n) + ":" + (o < 10 ? "0" + o : o);
  },
  format(e, t) {
    if (e && "object" == typeof t) {
      for (var n in t) {
        if (null != t[n]) {
          var o = new RegExp("({" + n + "})", "g");
          e = e.replace(o, t[n]);
        }
      }
    }
    return e;
  },
  webCopyString(e) {
    var t = e + "";
    var n = document.createElement("textarea");
    n.value = t;
    n.setAttribute("readonly", "");
    n.style.contain = "strict";
    n.style.position = "absolute";
    n.style.left = "-9999px";
    n.style.fontSize = "12pt";
    var o = getSelection();
    var i = false;
    o.rangeCount > 0 && (i = o.getRangeAt(0));
    document.body.appendChild(n);
    n.select();
    n.selectionStart = 0;
    n.selectionEnd = t.length;
    var s = false;
    try {
      s = document.execCommand("copy");
    } catch (a) {}
    document.body.removeChild(n);
    if (i) {
      o.removeAllRanges();
      o.addRange(i);
    }
    return s;
  }
};